home *** CD-ROM | disk | FTP | other *** search
- ;; findit.mut : search or search and replace across multiple files.
- ;; Uses grep to search for a string in many files. With arg (C-U), do a
- ;; search and replace across a bunch of files.
- ;; C Durland Public Domain
-
- (const
- GREP "/bin/grep -Fil " ;; fixed string, ignore case, one match per file
- )
-
- (include me2.h)
-
- (bool replace-em still-finding)
- (int scrbuf)
- (string look-for replace-with)
-
- (defun
- MAIN
- {
- (still-finding FALSE)
- (bind-to-key "showit" "C-xC-n")
- }
- findit
- {
- (string file-spec)
-
- (look-for (ask "Look for: "))
-
- (if (replace-em (arg-flag)) ;; if C-U, then replace else search
- (replace-with (ask 'Replace "' look-for '" with: ')))
-
- (file-spec (ask 'Look for "' look-for '" in: '))
-
- (if (== -2 (scrbuf (attached-buffer "*findit-list*")))
- (scrbuf (create-buffer "*findit-list*" BFHooHum)))
- (current-buffer scrbuf)
-
- (clear-buffer)
-
- (if (not
- (OS-filter (concat GREP '"' look-for '" ' file-spec) -1 -1 TRUE))
- (halt))
- (update) ;; screen is garbaged by (OS-filter)
-
- (still-finding TRUE)
- (showit)
- }
- showit
- {
- (if (not still-finding) { (msg "Not looking for anything!") (done) })
-
- (current-buffer scrbuf)
- (if (looking-at '\(.+\)') ;; get the next file we need to look at
- {
- (forward-line 1)
- (visit-file (get-matched '\1')) ;(delete-other-windows)
- ;(update) ;;
- (if replace-em (query-replace look-for replace-with)
- (isearch TRUE look-for) ;(search-forward look-for)
- )
- }
- {
- (free-buffer scrbuf)
- (still-finding FALSE)
- (msg "All done.")
- })
- }
- )
-